package com.ybkj.chat.module.dynamic.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.ybkj.chat.R;
import com.ybkj.chat.bean.Expand1Item;
import com.ybkj.chat.bean.ExpandItem;
import com.ybkj.chat.utils.ToastUtil;

import java.util.List;

public class ChooseFriendAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ChooseFriendAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.recycle_item_pickcreat_expand_1);
        addItemType(TYPE_LEVEL_1, R.layout.recycle_item_pickcreat_expand_2);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case TYPE_LEVEL_0:
                final ExpandItem item0 = (ExpandItem) item;
                helper.setText(R.id.groupName, item0.getTitle());
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = helper.getAdapterPosition();
                        if (item0.isExpanded()) {
                            collapse(pos);
                            ToastUtil.showShort("收起：" + item0.getTitle());
                        } else {
                            expand(pos);
                            ToastUtil.showShort("展开：" + item0.getTitle());
                        }
                    }
                });

                break;
            case TYPE_LEVEL_1:
                final Expand1Item item1 = (Expand1Item) item;
                helper.setText(R.id.item_name, item1.getTitle());
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ToastUtil.showShort("点击" + item1.getTitle());
                    }
                });
                break;
        }
    }

}
